#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        string x;
        cout << x;
        int arr[26] = { 0 };
        for (int i = 0; i < x.size() - 1; i++)
        {
            arr[x[i] - 'a']++;
        }

        int max = 0;
        char ch;
        for (int i = 0; i < 26; i++)
        {
            if (max < arr[i])
            {
                max = arr[i];
                ch = x[i + 'a'];
            }
        }

        cout << ch << ' ' << max << endl;
    }
}